/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('linkwan', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetKpmEncryptedNodeTuplesByOrderIdRequest {
  orderId?: long(name='OrderId'),
}

model GetKpmEncryptedNodeTuplesByOrderIdResponseBody = {
  code?: string(name='Code'),
  dynamicCode?: string(name='DynamicCode'),
  dynamicMessage?: string(name='DynamicMessage'),
  encryptedNodeTuples?: {
    encryptedNodeTuple?: [ 
    {
      appKeyKcv?: string(name='AppKeyKcv'),
      devEui?: string(name='DevEui'),
      encryptedAppKey?: string(name='EncryptedAppKey'),
      encryptedGenAppKey?: string(name='EncryptedGenAppKey'),
      encryptedNwkKey?: string(name='EncryptedNwkKey'),
      genAppKeyKcv?: string(name='GenAppKeyKcv'),
      loraVersion?: string(name='LoraVersion'),
      nwkKeyKcv?: string(name='NwkKeyKcv'),
      pinCode?: string(name='PinCode'),
    }
  ](name='EncryptedNodeTuple')
  }(name='EncryptedNodeTuples'),
  encryptedSessionZmk?: string(name='EncryptedSessionZmk'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model GetKpmEncryptedNodeTuplesByOrderIdResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetKpmEncryptedNodeTuplesByOrderIdResponseBody(name='body'),
}

async function getKpmEncryptedNodeTuplesByOrderIdWithOptions(request: GetKpmEncryptedNodeTuplesByOrderIdRequest, runtime: Util.RuntimeOptions): GetKpmEncryptedNodeTuplesByOrderIdResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.orderId)) {
    body['OrderId'] = request.orderId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetKpmEncryptedNodeTuplesByOrderId',
    version = '2018-10-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getKpmEncryptedNodeTuplesByOrderId(request: GetKpmEncryptedNodeTuplesByOrderIdRequest): GetKpmEncryptedNodeTuplesByOrderIdResponse {
  var runtime = new Util.RuntimeOptions{};
  return getKpmEncryptedNodeTuplesByOrderIdWithOptions(request, runtime);
}

model SubmitKpmEncryptedNodeTupleOrderRequest {
  loraVersion?: string(name='LoraVersion'),
  requiredCount?: long(name='RequiredCount'),
}

model SubmitKpmEncryptedNodeTupleOrderResponseBody = {
  code?: string(name='Code'),
  dynamicCode?: string(name='DynamicCode'),
  dynamicMessage?: string(name='DynamicMessage'),
  message?: string(name='Message'),
  orderId?: long(name='OrderId'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model SubmitKpmEncryptedNodeTupleOrderResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: SubmitKpmEncryptedNodeTupleOrderResponseBody(name='body'),
}

async function submitKpmEncryptedNodeTupleOrderWithOptions(request: SubmitKpmEncryptedNodeTupleOrderRequest, runtime: Util.RuntimeOptions): SubmitKpmEncryptedNodeTupleOrderResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.loraVersion)) {
    body['LoraVersion'] = request.loraVersion;
  }
  if (!Util.isUnset(request.requiredCount)) {
    body['RequiredCount'] = request.requiredCount;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SubmitKpmEncryptedNodeTupleOrder',
    version = '2018-10-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function submitKpmEncryptedNodeTupleOrder(request: SubmitKpmEncryptedNodeTupleOrderRequest): SubmitKpmEncryptedNodeTupleOrderResponse {
  var runtime = new Util.RuntimeOptions{};
  return submitKpmEncryptedNodeTupleOrderWithOptions(request, runtime);
}

